const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getLowestOfferListingsForASIN = {};
getLowestOfferListingsForASIN.generateOption = function(seller_id, mws_auth_token, marketplaceId, asin, itemCondition){
  const baseOption = {
    'Version': '2011-10-01',
    'Action': 'GetLowestPricedOffersForASIN',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'MarketplaceId': marketplaceId,
    'ASIN': asin,
    'ItemCondition': itemCondition
  };

  return baseOption;
};

getLowestOfferListingsForASIN._ = function(options) {
  if (!isProduction) {
    return amazonMws.products.searchFor(options);
  } else {
    console.error("bot not implemented!");
  }
};

getLowestOfferListingsForASIN.getLowestOfferListingsForASIN = function(seller_id, mws_auth_token, asin, itemCondition) {
  return this._(this.generateOption(seller_id, mws_auth_token, asin, itemCondition));
};

module.exports = getLowestOfferListingsForASIN;